package qianfeng.com.meijiadaka.adapter.shop_details;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import qianfeng.com.meijiadaka.R;
import qianfeng.com.meijiadaka.bean.detail.SpecialBeanBelow;

/**
 * Created by Think on 2017/2/7.
 */

public class SpeaialDetailsCommend2RecyclerAdapter extends RecyclerView.Adapter<SpeaialDetailsCommend2RecyclerAdapter.MyViewHolder> {
    private List<Object> list;
    private SpecialBeanBelow bean;
    private Context context;
    OnItemClickListener mListener;
    private RecyclerView rv;


    @Override
    public void onAttachedToRecyclerView(RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
        rv = recyclerView;
    }

    public interface OnItemClickListener{
        void onClick(int index);
    }
    public void setOnItemClickListener(OnItemClickListener itemClickListener) {
        this.mListener=itemClickListener;
    }


    public SpeaialDetailsCommend2RecyclerAdapter(SpecialBeanBelow bean, Context context) {
        this.bean = bean;
        this.context = context;
        list = new ArrayList<>();
        list.addAll(bean.getResult().getComments().get(0).getReplys());
        Log.e("SpeaialDetailsCommend2RecyclerAdapter: ",list.size()+"");

    }

    //重写onCreateViewHolder方法，返回一个自定义的ViewHolder
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        final View view = LayoutInflater.from(context).inflate(R.layout.specia_details_list_item4_rvitem_commend_rvitem,parent,false);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mListener!=null){
                    mListener.onClick(rv.getChildAdapterPosition(view));
                }
            }
        });
        return new MyViewHolder(view);
    }

    //填充onCreateViewHolder方法返回的holder中的控件
    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.tv.setText(bean.getResult().getComments().get(0).getReplys().get(position).getAuthor());
        holder.tv1.setText(bean.getResult().getComments().get(0).getReplys().get(position).getContent());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    class MyViewHolder extends RecyclerView.ViewHolder{

        TextView tv,tv1;
        public MyViewHolder(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.specia_details_list4_rvitem_commend_recyclerView_tvitem1);
            tv1 = (TextView) itemView.findViewById(R.id.specia_details_list4_rvitem_commend_recyclerView_tvitem2);
        }
    }
}
